#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import argparse

sys.path.insert(0, os.path.expanduser('~') + '/lib/python')

from time import sleep


def func1(arg):
    print('func1: {}'.format(arg))


def func2(arg):
    print('func2: {}'.format(arg))

if __name__ == '__main__':
    choices = {'func1': func1, 'func2': func2}
    parser = argparse.ArgumentParser(description='Send and receive UDP locally')
    parser.add_argument('role', choices=choices, help='which role to play')
    parser.add_argument('-p', metavar='PORT', type=int, default=1060, help='UDP port (default 1060)')
    args = parser.parse_args()
    function = choices[args.role]
    function(args.p)


'''
import mylib.hw.disk as Disk
import mylib.hw.net as Net
import mylib.util as util

prevnw = 0
prevnr = 0
ndev = 'eth0:'
prevdw = 0
prevdr = 0
ddev = 'sdj'
while True:
    nio = Net.get_net_io(ndev)
    nw = nio[ndev]['wbytes'] - prevnw
    nr = nio[ndev]['rbytes'] - prevnr
    prevnw = nio[ndev]['wbytes']
    prevnr = nio[ndev]['rbytes']
    nws = util.hsize(nw)
    nrs = util.hsize(nr)

    dio = Disk.diskstats_parse(ddev)
    dw = dio[ddev]['rd_sectors'] - prevdw
    dr = dio[ddev]['wr_sectors'] - prevdr
    prevdw = dio[ddev]['rd_sectors']
    prevdr = dio[ddev]['wr_sectors']
    dws = util.hsize(dw * 4096)
    drs = util.hsize(dr * 4096)

    print("[Net r : " + nrs + ", w : " + nws + "] [Disk r : " + drs + ", w : " + dws + ']')
    #print(dio['sdj1'])
    sleep(1)
'''